[XEND] Add debug class to Xen API plus non-standard debug.wait().
authorAlastair Tse <atse@xensource.com>
Wed, 24 Jan 2007 15:59:09 +0000 (15:59 +0000)
committerAlastair Tse <atse@xensource.com>
Wed, 24 Jan 2007 15:59:09 +0000 (15:59 +0000)
debug.wait(seconds) will just do a time.sleep() so the task progress
support can be tested.

Signed-off-by: Alastair Tse <atse@xensource.com>
tools/python/scripts/xapi.py
tools/python/xen/xend/XendAPI.py

index 8e17354597adf9358a9bbb9eb9552179a810e622..930395b6a86ab8bfaa79c7be3b71e2aeba2330a8 100644 (file)
@@ -662,7 +662,7 @@ def xapi_debug_wait(args, async = False):
     if len(args) > 0:
         secs = int(args[0])
     server, session = connect()
-    task_uuid = execute(server, 'Debug.wait', (session, secs), async=async)
+    task_uuid = execute(server, 'debug.wait', (session, secs), async=async)
     print 'Task UUID: %s' % task_uuid
 
 #
index 0c7355a662ef54a42c7e91647fa876afd878fb8d..309bd20bbd883b4d187f7c047fa4b035c48da742 100644 (file)
@@ -260,6 +260,17 @@ def valid_task(func):
            _check_ref(XendTaskManager.get_task,
                       'TASK_HANDLE_INVALID', func, *args, **kwargs)
 
+def valid_debug(func):
+    """Decorator to verify if task_ref is valid before calling
+    method.
+
+    @param func: function with params: (self, session, task_ref)
+    @rtype: callable object
+    """
+    return lambda *args, **kwargs: \
+           _check_ref(lambda r: r in XendAPI._debug,
+                      'TASK_HANDLE_INVALID', func, *args, **kwargs)
+
 # -----------------------------
 # Bridge to Legacy XM API calls
 # -----------------------------
@@ -300,6 +311,7 @@ class XendAPI(object):
 
     __decorated__ = False
     __init_lock__ = threading.Lock()
+    _debug = {}
     
     def __new__(cls, *args, **kwds):
         """ Override __new__ to decorate the class only once.
@@ -337,6 +349,7 @@ class XendAPI(object):
             'SR'      : valid_sr,
             'PIF'     : valid_pif,
             'task'    : valid_task,
+            'debug'   : valid_debug,
         }
 
         # Cheat methods
@@ -1866,6 +1879,40 @@ class XendAPI(object):
         return xen_api_success_void()
 
 
+    # Xen API: Class debug
+    # ----------------------------------------------------------------
+
+    debug_methods = [('destroy', None),
+                     ('get_record', 'debug')]
+    debug_funcs = [('wait', None),
+                   ('return_failure', None)]
+    
+    def debug_wait(self, session, wait_secs):
+         import time
+         prog_units = 100/float(wait_secs)
+         for i in range(int(wait_secs)):
+             XendTask.log_progress(prog_units * i, prog_units * (i + 1),
+                                   time.sleep, 1)
+         return xen_api_success_void()
+
+
+    def debug_return_failure(self, session):
+        return xen_api_error(['DEBUG_FAIL', session])
+
+    def debug_create(self, session):
+        debug_uuid = uuid.createString()
+        self._debug[debug_uuid] = None
+        return xen_api_success(debug_uuid)
+
+    def debug_destroy(self, session, debug_ref):
+        del self._debug[debug_ref]
+        return xen_api_success_void()
+
+    def debug_get_record(self, session, debug_ref):
+        return xen_api_success({'uuid': debug_ref})
+
+             
+
 class XendAPIAsyncProxy:
     """ A redirector for Async.Class.function calls to XendAPI
     but wraps the call for use with the XendTaskManager.